<template>
  <div class="app-bg auto">
    <div class="auto" style="background:#108ADD;text-align:center; padding:10px 0px;color:#FFF;font-size: 18px;">
      博能燃气手机抄表
    </div>
      <div class="row app-input">
        <label class="col-xs-4 control-label text-left">册号</label>
        <input class="col-xs-8" v-model="model.f_meterbook_id" placeholder="请输入查询册号">
      </div>
      <div class="row app-input">
        <label class="col-xs-4 control-label text-left">开始时间</label>
        <datepicker
          :value.sync="model.f_start_date"
          :disabled-days-of-week="[]"
          :format="'yyyy-MM-dd'"
          :show-rest-button="reset"
          v-model="model.f_start_date"
          condition="f_checkdate >= '{}'">
        </datepicker>
      </div>
      <div class="row app-input">
        <label class="col-xs-4 control-label text-left">结束时间</label>
        <datepicker
          :value.sync="model.f_end_date"
          :disabled-days-of-week="[]"
          :format="'yyyy-MM-dd'"
          :show-rest-button="reset"
          v-model="model.f_end_date"
          condition="f_checkdate >= '{}'">
        </datepicker>
      </div>
      <div class="row app-input">
        <label class="col-xs-4 control-label text-left">缴费户数</label>
        <input class="col-xs-8" v-model="user.number_value"  disabled>
      </div>
      <!-- <div class="row app-input">
        <label class="col-xs-4 control-label text-left">预缴费金额</label>
        <input class="col-xs-8" v-model="user.f_preamount"  disabled>
      </div> -->
      <div class="row app-input">
        <label class="col-xs-4 control-label text-left">实缴费金额</label>
        <input class="col-xs-8" v-model="user.money_value"  disabled>
      </div>
      <div class="app-btn">
        <button type="button" name="button" class="btn btn-primary"  @click="this.$back()">
          <span  class="glyphicon glyphicon-remove-circle" style="margin-right: 15px;"></span>返回
        </button>
        <button type="button" name="button" class="btn btn-primary" @click="search()" >
          <span  class="glyphicon glyphicon-floppy-disk" style="margin-right: 15px;" ></span>查询
        </button>
      </div>
  </div>
</template>

<script>
import * as Util from '../Util'
import appData from '../../../src/components/appData'
import config from '../../../src/components/config'
import Vue from 'vue'
import co from 'co'
let getsumnumber = function * (self) {
  // let getdata = yield self.$post(config.resultUrl +'rs/sql/SumNumber',self.model,{resolveMsg: null, rejectMsg: null})
  // let getdata = yield self.$post('rs/sql/SumNumber',self.model,{resolveMsg: null, rejectMsg: null})

  let condition = `1=1 and f_operator = '${appData.loginUser.logininfo[0].f_bieming}' and  f_charge_state = '有效'`
  for (var key in self.model) {
    console.log(key);
    if (self.model[key] !== '' ) {
      if (key === 'f_start_date' || key === 'f_end_date' ) {
        if (key === 'f_start_date') {
            condition  += ` and f_delivery_date >= '${self.model['f_start_date']} 00:00:00' `
        } else if (key === 'f_end_date') {
          condition  += ` and f_delivery_date <= '${self.model['f_end_date']} 23:59:59'`
        }

      } else {
        condition  = condition + ` and ${key} = '${self.model[key]}'`
      }
      console.log(condition);
    }
  }
  let items = `COUNT(id) number_value,isnull(sum(f_preamount),0) f_preamount, isnull(SUM(f_collection),0) money_value`
  let getdata =   yield self.$post(config.resultUrl + 'rs/sql/singleTable_OrderBy', {data:{condition: condition ,items: items ,tablename: 't_sellingwater',orderitem:'number_value'}},
  {resolveMsg: null, rejectMsg: null})
  console.log(getdata);
  self.user.number_value = getdata.data[0].number_value
  self.user.money_value = getdata.data[0].money_value
  self.user.f_preamount = getdata.data[0].f_preamount


}
export default {
  title: '收费统计',
  props: ['row','userfiles'],
  data(){
    return{
      model: {
        f_operator: appData.loginUser.logininfo[0].f_bieming,
        f_meterbook_id: '',
        f_start_date: Util.toStandardDateString(),
        f_end_date: Util.toStandardDateString(),
      },
      user: {
        number_value: 0,
        money_value: 0,
        f_preamount: 0
      }
    }
  },
  methods: {
    //汇总查询
    search () {
      let gen = getsumnumber(this)
      return co(gen)
    }
  }
}
</script>
